import time

from selenium.webdriver.common.by import By
from test.BlogLoginTest import login
from common.Utils import BlogDriver
#首页测试
class BlogList:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.137.19.140:9090/blog_list.html"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)

    def check(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > img")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > span")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(4)")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(5)")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(6)")

    def ListTestByLogin(self):
        #先检查导航条
        self.check()
        #截屏
        BlogDriver.getScreenShot()
        #检查用户昵称
        txt2=self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3").text
        print(txt2)
        #检查头像
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > img")
        #检查标题
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.title")
        #检查内容
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.desc")
        #检查“查看全文”
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > a")

        #点击注销
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(6)").click()

    def ListTestByLoginAgain(self):
        #检查是否有这个按钮，有则说明注销成功
        self.driver.find_element(By.CSS_SELECTOR,"#submit")
        #再重新登陆
        time.sleep(0.5)
        login.LoginSucTest()
        #点击查看全文按钮，进行详情页测试，以2025-03-16 22:11这个时间的博客为例
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > a").click()




List=BlogList()







